//
//  PTRecorderFrame.m
//  PocketTutor
//
//  Created by yate1996 on 15/6/9.
//  Copyright (c) 2015年 yate1996. All rights reserved.
//

#import "PTRecorderFrame.h"
#import "PTRecorder.h"
@implementation PTRecorderFrame

-(void)setRecorder:(PTRecorder *)recorder
{
    _recorder = recorder;
    
    CGFloat iconX = PTRecorderCellInset ;
    CGFloat iconY = PTRecorderCellInset ;
    CGFloat iconW = 55;
    CGFloat iconH = 55;
    self.lessonIconFrame = CGRectMake(iconX, iconY, iconW, iconH);
    
    
    CGFloat titleX = CGRectGetMaxX(self.lessonIconFrame) + PTRecorderCellMargin;
    CGFloat titleY = iconY;
    NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];
    textAttr[NSFontAttributeName] = PTHelveticaNeue14;
    CGSize titleSize = [recorder.lessonTitle sizeWithAttributes:textAttr];
    self.lessonTitleFrame = (CGRect){{titleX,titleY},titleSize};
    
    
    CGFloat nameX = titleX;
    CGFloat nameY = CGRectGetMaxY(self.lessonTitleFrame)+PTRecorderCellMargin * 0.4;
    textAttr[NSFontAttributeName] = PTHelveticaNeueLight14;
    titleSize = [recorder.teacherName sizeWithAttributes:textAttr];
    self.teacherNameFrame = (CGRect){{nameX,nameY},titleSize};
    
    
    CGFloat bottomButtonX = nameX;
    CGFloat bottomButtonY = CGRectGetMaxY(self.teacherNameFrame)+PTRecorderCellMargin* 0.4;
    textAttr[NSFontAttributeName] = PTHelveticaNeueLight12;
    titleSize = [recorder.countDown sizeWithAttributes:textAttr];
    self.countDownFrame = (CGRect){{bottomButtonX,bottomButtonY},titleSize.width,titleSize.height};
    
    
    if([recorder.actionOrCancel isEqualToString: @"Read My Evaluation"])
    {
        textAttr[NSFontAttributeName] = PTHelveticaNeueLight12;
        titleSize = [recorder.countDown sizeWithAttributes:textAttr];
        
    }
    
    
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = [UIScreen mainScreen].bounds.size.width;
    CGFloat h = CGRectGetMaxY(self.lessonIconFrame) + PTRecorderCellInset;
    self.frame = CGRectMake(x,y, w, h);
    self.cellHeight = h;
    
    CGFloat rightButtonY = ( h - 28 )/2;
    CGFloat rightButtonX = [UIScreen mainScreen].bounds.size.width - 76 - PTRecorderCellMargin;
    self.actionOrCancelFrame = (CGRect){{rightButtonX,rightButtonY},76,28};
}
@end
